package com.example.demo2.util;

import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

/**
 * @Description this class is a tool for transfer page from one to another
 */
public class TransferPage {

    public static void transfer(String str, String title, int height, int width) {
        URL resource = null;
        try {
            resource = new File("src/main/resources/fxml/" + str + ".fxml").toURI().toURL();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        try {
            setScene(resource, title,width,height);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void setScene(URL url, String title,int width,int height) throws IOException {
        FXMLLoader loader = new FXMLLoader(url);
        loader.load();
        Parent root = loader.getRoot();
        Scene scene = new Scene(root, width, height);
        Stage newStage = new Stage();
        newStage.setTitle(title);
        newStage.setScene(scene);
        newStage.show();
    }
}
